//
//  TryHoneSystemhelper.m
//  TryHone
//
//  Created by TryHone on 17/5/25.
//  Copyright © 2017年 TryHone. All rights reserved.
//

#import "JFSystemHelper.h"
#import "JFStringHelper.h"
#import <UIKit/UIKit.h>
#import <sys/utsname.h>

@implementation JFSystemHelper
/**
 *
 *  获取系统应用版本号
 *
 *  @return 系统应用版本号
 */
+(NSString *)getAppVersion
{
    NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    return build;
}

/**
 *  获取应用名称
 *
 *  @return 应用名称
 */
+(NSString *)getAppName
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    //当前应用名称
    NSString *appCurName = [infoDictionary objectForKey:@"CFBundleName"];
    return appCurName;
}

/**
 *
 *  获取应用描述名
 *
 *  @return 应用描述
 */
+(NSString *)getAppDisplayName
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    //当前应用描述名称
    NSString *appCurDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    return appCurDisplayName;
}

/**
 *  @Author , 2014-12-23 16:12:06
 *
 *  获取应用唯一值
 *
 *  @return 应用唯一值
 */
+(NSString *)getAppIdentifier
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    //当前应用唯一描述
    NSString *appIdentifier = [infoDictionary objectForKey:@"CFBundleIdentifier"];
    return appIdentifier;
}

/**
 *  @Author , 2014-12-23 16:12:57
 *
 *  获取系统最低版本
 *
 *  @return 获取支持的系统最低版本
 */
+(NSString *)getAppLowerSystemVersion
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    //当前应用支持系统的最低版本
    NSString *appLowerSystemVersion = [infoDictionary objectForKey:@"CFBundleInfoDictionaryVersion"];
    return appLowerSystemVersion;
}

/**
 *  @Author , 2014-12-23 16:12:10
 *
 *  获取应用的URL标示
 *
 *  @return
 */
+(NSString *)getAppURLName
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSArray *CFBundleURLTypes = (NSArray *)[infoDictionary objectForKey:@"CFBundleURLTypes"];
    if (CFBundleURLTypes && CFBundleURLTypes.count > 0)
    {
        NSDictionary *dic = CFBundleURLTypes[0];
        return (NSString *)[dic objectForKey:@"CFBundleURLName"];
    }
    return @"";
}

/**
  2014-12-23 16:12:03
 *
 *  获取URLSchemes
 *
 *  @return
 */
+(NSString *)getAppURLScheme
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSArray *CFBundleURLTypes = (NSArray *)[infoDictionary objectForKey:@"CFBundleURLTypes"];
    if (CFBundleURLTypes && CFBundleURLTypes.count > 0)
    {
        NSDictionary *dic = CFBundleURLTypes[0];
        NSArray *URLSchemes = (NSArray *)[dic objectForKey:@"CFBundleURLSchemes"];
        if (URLSchemes && URLSchemes.count > 0)
        {
            return (NSString *)URLSchemes[0];
        }
    }
    return @"";
}

+(NSString*)getDeviceType{
 
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
    if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4";
    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
    if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
    if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c";
    if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c";
    if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s";
    if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s";
    if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    // 日行两款手机型号均为日本独占，可能使用索尼FeliCa支付方案而不是苹果支付
    if ([platform isEqualToString:@"iPhone9,1"])    return @"国行、日版、港行iPhone 7";
    if ([platform isEqualToString:@"iPhone9,2"])    return @"港行、国行iPhone 7 Plus";
    if ([platform isEqualToString:@"iPhone9,3"])    return @"美版、台版iPhone 7";
    if ([platform isEqualToString:@"iPhone9,4"])    return @"美版、台版iPhone 7 Plus";
    if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
    if ([platform isEqualToString:@"iPhone10,1"])   return @"iPhone 8";
    if ([platform isEqualToString:@"iPhone10,4"])   return @"iPhone 8";
    if ([platform isEqualToString:@"iPhone10,2"])   return @"iPhone 8 Plus";
    if ([platform isEqualToString:@"iPhone10,5"])   return @"iPhone 8 Plus";
    if ([platform isEqualToString:@"iPhone10,3"])   return @"iPhone X";
    if ([platform isEqualToString:@"iPhone10,6"])   return @"iPhone X";
    if ([platform isEqualToString:@"iPhone11,8"])   return @"iPhone XR";
    if ([platform isEqualToString:@"iPhone11,2"])   return @"iPhone XS";
    if ([platform isEqualToString:@"iPhone11,6"])   return @"iPhone XS Max";
    if ([platform isEqualToString:@"iPhone11,4"])   return @"iPhone XS Max";
    if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
    if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
    if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
    if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
    if ([platform isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";
    if ([platform isEqualToString:@"iPad1,1"]) return @"iPad 1G";
    if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2";
    if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini 1G";
    if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini 1G";
    if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini 1G";
    if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,2"]) return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,3"]) return @"iPad 3";
    if ([platform isEqualToString:@"iPad3,4"]) return @"iPad 4";
    if ([platform isEqualToString:@"iPad3,5"]) return @"iPad 4";
    if ([platform isEqualToString:@"iPad3,6"]) return @"iPad 4";
    if ([platform isEqualToString:@"iPad4,1"]) return @"iPad Air";
    if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air";
    if ([platform isEqualToString:@"iPad4,3"]) return @"iPad Air";
    if ([platform isEqualToString:@"iPad4,4"]) return @"iPad Mini 2G";
    if ([platform isEqualToString:@"iPad4,5"]) return @"iPad Mini 2G";
    if ([platform isEqualToString:@"iPad4,6"]) return @"iPad Mini 2G";
    if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
    if ([platform isEqualToString:@"x86_64"]) return @"iPhone Simulator";
    return platform;

}


#pragma mark--功能类
/**
 *  @Author TryHone, 2016年05月31日13:55:46
 *  拨打电话，打完电话不会到app
 */
+(void)callPhone:(NSString*)phonenumber{
    
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phonenumber]];
    [[UIApplication sharedApplication] openURL:phoneURL];
}
/**
 *  @Author TryHone, 2016年05月31日13:55:46
 *  拨打电话，打完电话回到app
 */
+(void)callPhoneEndBack:(NSString*)phonenumber{
    [self callPhone:phonenumber];
}

/**
 *  @Author TryHone, 2016年05月31日13:55:46
 *  发送短信，设置电话号码，不能初始化短信内容
 */
+(void)sendSms:(NSString*)phonenumber{
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"sms:%@",phonenumber]];
    [[UIApplication sharedApplication] openURL:phoneURL];
}

/**
 *  @Author TryHone, 2016年05月31日13:55:46
 *  调用safari 打开一个网页
 */
+(void)openUrl:(NSString*)url{
    
    if ([JFStringHelper isNotEmpty:url]) {
        
        NSString* tempurl=[url lowercaseString];
        
        if (![JFStringHelper string:url beginWith:@"http"]) {
            
            tempurl=[NSString stringWithFormat:@"http://%@",url];
        }
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
            [[UIApplication sharedApplication]  openURL:[NSURL URLWithString:tempurl] options:@{} completionHandler:^(BOOL success) {
                
            }];
        }else{
           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tempurl]];
        }
    }
}


@end
